
#include <sys/cdefs.h>

#if !defined(_KERNEL) && !defined(_STANDALONE)
#include "namespace.h"
#include <assert.h>
#include <ctype.h>
#include <string.h>
#ifdef __weak_alias
__weak_alias(strcasecmp,_strcasecmp)
__weak_alias(strncasecmp,_strncasecmp)
#endif
#else
#include <lib/libkern/libkern.h>
#include <machine/limits.h>
#endif 

int
strncasecmp(const char *s1, const char *s2, size_t n)
{

	_DIAGASSERT(s1 != NULL);
	_DIAGASSERT(s2 != NULL);

	if (n != 0) {
		const unsigned char *us1 = (const unsigned char *)s1,
				*us2 = (const unsigned char *)s2;

		do {
			if (tolower(*us1) != tolower(*us2++))
				return (tolower(*us1) - tolower(*--us2));
			if (*us1++ == '\0')
				break;
		} while (--n != 0);
	}
	return (0);
}
